/*
指针数组及其排序
功能:通过strcmp函数对字符串进行排序
 
*/
#include<stdio.h>
#include<string.h>

int main1 (void)
{
    char * a [4] = {"ddddd","bbbbb","aaaaa","ccccc"};
    //int n = sizeof(a) /strlen(a[0]);
    
    char *tmp = NULL;//用于交换两个字符串指针
    int i,j;
    printf ("排序前\n");
    for (i = 0;i< 4;i++)
    {
        printf ("%s ",a[i] );
    }
    
    
    for (i = 0;i< 4 ;i++)//选择法排序
    {
        for (j = i+1;j<4;j++)
        {
            if(strcmp(a[i],a[j])>0)
            {
                tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
            }
        }
    }
    printf ("\n排序后\n");
    for (i = 0;i< 4;i++)
    {
        printf ("%s ",a[i] );
    }
    printf("\n");
    return  0;
    
}
void pr_parr(char **a,int n)
{
    int i;
    for (i = 0;i< n;i++)
    {
        printf ("%s ",a[i] );
    }
    printf ("\n");
}
void sort_parr(char **a,int n)
{
    int i;int j;
    char * tmp = NULL;
      for (i = 0;i< 4 ;i++)//选择法排序
    {
        for (j = i+1;j<4;j++)
        {
            if(strcmp(a[i],a[j])>0)
            {
                tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
            }
        }
    }
}
int main (void)
{
    char * a [4] = {"ddddd","bbbbb","aaaaa","ccccc"};
    int n = sizeof(a) /sizeof (a[0]);
    //int ret = 0;
    printf ("排序前\n");
    pr_parr(a,n);
    
    sort_parr(a,n);
    printf ("排序后\n");
    pr_parr(a,n);
    
    return 0;
}
